<?php
    function findfriends ($eventid, $con, $fb) {        
	    $event_id = $eventid;
	    $userfriends=$fb->api('/me/friends');
	    
	    //echo $con."<br/>";
	    //echo $userfriends->id[0];
	    $query = "select seat_name, row_no, section, user_id from hh_seat_allocate_".$event_id;	
	    //echo $query;
	    //echo "<br/>";
	    $attendees=mysql_query($query, $con);
	    if(! $attendees )
        {
           die('Could not get data: ' . mysql_error());
        }
	    $i=0;
	    while($row = mysql_fetch_array($attendees, MYSQL_ASSOC))
        {
	        $seatname[$i]=$row['seat_name'];
		    $rowno[$i]=$row['row_no'];
		    $sect[$i]=$row['section'];
		    $userid[$i]=$row['user_id'];
		    $i=$i+1;
            /*echo "Seat Name :{$row['seat_name']}  <br> ".
             "Row No : {$row['row_no']} <br> ".
             "Section : {$row['section']} <br> ".
			 "User ID : {$row['user_id']} <br> ".
             "--------------------------------<br>";*/
			 
        } 
        //echo "Fetched data successfully ".$i."<br/>";
        $k=0;
	    foreach ($userfriends as $friends) {
            foreach ($friends as $friend) {
            //do something with the friend, but you only have id and name
		       if (isset($friend['id'])) { 
		           $id1 = $friend['id'];
                   $name1 = $friend['name'];
		           // echo $id1 . $name1 . "<br/>";
		           for ($j=0;$j<$i; $j++){             
		               //$query=$query.$id
			           if ($id1==$userid[$j]) {
                           $data->ret_seatname[$k]=$seatname[$j];
		                   $data->ret_rowno[$k]=$rowno[$j];
		                   $data->ret_sect[$k]=$sect[$j];
		                   $data->ret_userid[$k]=$userid[$j];
                           $k=$k+1;				
			           } 		     
		           }
		       }		 
            }
	    }
	
	    /*for ($l=0;$l<$k;$l++) {
	        echo $data->ret_seatname[$l]." ".$data->ret_rowno[$l]." ".$data->ret_sect[$l]." ".$data->ret_userid[$l]."<br/>";
	    }*/
	
	    mysql_free_result($attendees);
	    return $data;
	}
	
	function countData($data1) {
	    foreach ($data1 as $data){
	       $k=0;
		   foreach ($data as $key) {
	          $k=$k+1;        
		   }
	    }
		return $k;
	}
	
/*	require_once 'constants.php';
	$eventID = '428103803973147';
	$con = get_connection();
    $data = findfriends($eventID, $con, $fb);	
	$k = countData($data);
	
	echo "Count of the elements:".$k."<br>";
	
	for ($l=0; $l<$k;$l++){
	    echo $data->ret_seatname[$l]." ".$data->ret_rowno[$l]." ".$data->ret_sect[$l]." ".$data->ret_userid[$l]."<br/>";
	  
	}*/
?>